package com.xuebang.admin.entity;

import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;
@Table(name="operators")
public class Operator {
	@Id
	private Long operatorId	;//	操作员编码	Yes
	
	@Column
	private String name	;//	名字	No
	
	@Column
	private String loginName	;//	登录名	No
	
	@Column
	private String passwd	;//	密码	No
	private String oldPasswd	;//	当前密码
	
	@Column
	private String email	;//	邮箱	No
	
	@Column
	private String mobile	;//	手机	No
	
	@Column
	private Date createDate	;//	创建日期	No
	
	@Column
	private Date modifyDate	;//	修改日期	No
	
	@Column
	private Date lastLoginDate	;//	最后的登录日期	No
	
	@Column
	private Long departmentId	;//	部门编码	No
	
	@Column
	private Long positionId	;//职位编码	No
	
	@Column
	private String status	;//状态
	
	@Column
	private Long groupId	;//角色编码

//	private Position position;
	private OperatorGroups operatorGroups;

	
	public String getOldPasswd() {
		return oldPasswd;
	}

	public void setOldPasswd(String oldPasswd) {
		this.oldPasswd = oldPasswd;
	}

	public Long getGroupId() {
		return groupId;
	}

	public void setGroupId(Long groupId) {
		this.groupId = groupId;
	}

//	public Position getPosition() {
//		return position;
//	}
//
//	public void setPosition(Position position) {
//		this.position = position;
//	}

	public OperatorGroups getOperatorGroups() {
		return operatorGroups;
	}

	public void setOperatorGroups(OperatorGroups operatorGroups) {
		this.operatorGroups = operatorGroups;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public Long getOperatorId() {
		return operatorId;
	}

	public void setOperatorId(Long operatorId) {
		this.operatorId = operatorId;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getLoginName() {
		return loginName;
	}

	public void setLoginName(String loginName) {
		this.loginName = loginName;
	}

	public String getPasswd() {
		return passwd;
	}

	public void setPasswd(String passwd) {
		this.passwd = passwd;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	public Date getCreateDate() {
		return createDate;
	}

	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}

	public Date getModifyDate() {
		return modifyDate;
	}

	public void setModifyDate(Date modifyDate) {
		this.modifyDate = modifyDate;
	}

	public Date getLastLoginDate() {
		return lastLoginDate;
	}

	public void setLastLoginDate(Date lastLoginDate) {
		this.lastLoginDate = lastLoginDate;
	}

	public Long getDepartmentId() {
		return departmentId;
	}

	public void setDepartmentId(Long departmentId) {
		this.departmentId = departmentId;
	}

	public Long getPositionId() {
		return positionId;
	}

	public void setPositionId(Long positionId) {
		this.positionId = positionId;
	}
	/**
	 * 验证当前用户是否具备某个权限
	 * @param ruleId 权限id，operator_rules中的rule_id
	 * @return
	 */
	public boolean hasPerm(Long ruleId){
		if(this.operatorGroups!=null){
			List<OperatorRules> myPermissions = this.operatorGroups.getOperatorRulesList();
			if (myPermissions!=null){
				for(int i=0;i<myPermissions.size();i++){
					if(ruleId.equals(myPermissions.get(i).getRuleId())){
						return true;
					}
				}
			}
		}
		return false;
	}
	
}
